package com.dou361.ijkplayer.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by carolina on 2017/7/19.
 * 本类用于打赏适配数据
 */

public abstract class RewardGridAdapter extends BaseAdapter{
    private Context context;
    private String[] array;
    private int[]imgs;

    //构造器
    public RewardGridAdapter(Context context){
       this.context=context;

    }
    //传输数据
    public void setData(String[] array, int[] imgs){
        this.array=array;
        this.imgs=imgs;
    }
    @Override
    public int getCount() {
        return array.length;
    }

    @Override
    public Object getItem(int i) {
        return array[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        RewardViewHolder holder;
        if(view==null){
            view=getRes();
            holder=new RewardViewHolder();
            holder.img=view.findViewById(getImgId());
            holder.tv=view.findViewById(getTvId());
            view.setTag(holder);
        }else {
            holder = (RewardViewHolder) view.getTag();

        }
        holder.img.setImageResource(imgs[i]);
        holder.tv.setText(array[i]);
        return view;
    }
    class RewardViewHolder{
        ImageView img;
        TextView tv;
    }
    public abstract int getImgId();
    public abstract int getTvId();
        public abstract View getRes();
}
